#!/usr/bin/env python3
"""
    This script is used to generate xkeysyms.py from the X keysymdef.h definition
    header file.
"""
import os, os.path, sys
import re


template = '''\
keysyms = {
%s
}\
'''

def genkeysyms(path):
    XRE = r"#define\s+XK_(\S+)\s+(\S+)"
    ks = []
    for i in file(path):
        m = re.match(XRE, i)
        if m:
            ks.append(m.groups())

    lines = ["    '%s': %s," % i for i in ks]
    print(template % '\n'.join(lines))

if __name__ == "__main__":
    if len(sys.argv) != 2:
        sys.stderr.write("Usage: genkeysyms path/to/keysymdef.h\n")
        sys.exit(1)
    genkeysyms(sys.argv[1])
